package cn.kgm.single;

/**
 * @Version 1.8
 * @Author: Kappi
 * @Date: 2025-1-10 15:01
 * @Description: cn.kgm.single.SingleNumber
 */
public class SingleNumber {

//    public static int solution(int[] cards) {
//        // Edit your code here
//        AtomicReference<Integer> k = new AtomicReference<>();
//        Map<Integer,Integer> num = new HashMap<>();
//        for (int card : cards) {
//            num.put(card,1 + Optional.ofNullable(num.get(card)).orElse(0));
//        }
//        num.forEach((key,v)->{
//            if (v == 1){
//                k.set(key);
//            }
//        });
//        return k.get();
//    }

    // 官方正解
    public static int solution(int[] cards) {
        // Edit your code here
        int result = 0;
        for (int card : cards) {
            result ^= card;
        }
        return result;
    }

    public static void main(String[] args) {
        // Add your test cases here
        System.out.println(solution(new int[]{1, 1, 2, 2, 3, 3, 4, 5, 5}) == 4);
        System.out.println(solution(new int[]{0, 1, 0, 1, 2}) == 2);
    }
}
